
# Makefile for linux kernel modules

define linux-module

.PHONY: $(1)
$(1):
	$$(MAKE) -C $$(KDIR) M=$$(shell pwd)/$(1) modules

ifeq ($(USE_MODULE_CLEAN),y)
clean-$(1):
	$$(MAKE) -C $$(KDIR) M=$$(shell pwd)/$(1) clean
endif

ifeq ($(USE_MODULE_TEST_COMMAND),y)
insmod-$(1):
	@sudo insmod $$(shell pwd)/$(1)/$(1).ko
	dmesg

rmmod-$(1):
	@sudo rmmod $$(shell pwd)/$(1)/$(1).ko
	dmesg

reinst-$(1):
	-@sudo rmmod $$(shell pwd)/$(1)/$(1).ko
	-@sudo insmod $$(shell pwd)/$(1)/$(1).ko
	dmesg
endif

endef
